<?php
/**
 * Purpose:
 * 商品
 * File Name:
 * Item.php
 * Author:
 * 武当山道士<912900700@qq.com>
 * Create:
 * 2019/9/29 18:45
 */


namespace app\api\model;

use think\Db;
use app\common\GlobalConf;

class Item extends Base
{

    /**
     * @param $page
     * @param null $key_word
     * @param null $tag
     * @return null
     * @throws
     */
    public function searchItems($page=1, $key_word=null, $tag=null)
    {
        $where = [
            'status' => 1,
        ];
        if( !empty($key_word) ) {
            $where['name'] = ['like',"%$key_word%"];
        }
        if( !empty($type) ) {
            $where['tag'] = $tag;
        }
        $startPosition = ($page-1) * GlobalConf::PAGE_STEP;
        $list = Db::name('item')->field('*')->where($where)
            ->order('createtime desc')
            ->limit($startPosition, GlobalConf::PAGE_STEP)
            ->select();
        if( empty($list) ) return null;
        foreach ($list as $k=>$v) {
            $list[$k]['images'] = walk_image_str($v['images']);
            $list[$k]['thumbs'] = walk_image_str($v['thumbs']);
        }
        return $list;
    }
}